<?php
class tban extends CI_Controller {
	var $titp='Tban';
	var $url ='tban/';
	var $reg ='mision/';

	function index(){
		redirect($this->url.'filteredgrid');
	}

	function filteredgrid(){
		$this->load->library('rapyd');

		$grid = new datagrid_library();
		$grid->label = 'Lista de bancos';
		$grid->per_page = 40;
		$grid->cid = '';
		$grid->source('tban');

		$grid->column('nombre','Nombre del banco',true)->url('tban/dataedit/show/{id}');
		

		$grid->back_url = site_url($this->url.'mision');
		$grid->add_button(array('url'=>$this->url.'dataedit/create'));
		$grid->buttons('modify','save','undo','delete','back');
		$grid->build();

	        $action = "javascript:window.location.href='".site_url('/')."'";
		$grid->button('btn_reg', 'Regresar', $action, 'TR');
		$grid->build();



		$data['content'] = $grid->output;
		$data['head']    = $this->rapyd->head().script('jquery.js');
		$data['title']   = '';
		$this->load->view('view_ventanas_sola', $data);
	}

	function dataedit(){
		$this->load->library('rapyd');

		$edit = new dataedit_library();
		$edit->label = 'Lista de bancos';
		$edit->back_url = site_url($this->url.'filteredgrid');

		$edit->source('tban');
		$edit->pre_process(array('delete'), array($this, 'pre_delete'));

		$edit->field('input','nombre','Nombre')
			->rule('trim|unique|required');

		$edit->buttons('modify','save','undo','delete','back');

		$edit->build();
	
		$data['head']    = $this->rapyd->head();
		$data['content'] = $edit;
		$this->load->view('view_ventanas_sola', $data);

	}

	function pre_delete($model){
		$id = $model->get('id');

		$this->db->from('banco');
		$this->db->where('id_ban',$id);
		$cana = $this->db->count_all_results();

		if($cana==0){
			return true;
		}
		$model->error_string = '--No se puede eliminar un banco con datos almacenados.';
		return false;
	}
}

